#!/usr/bin/env python
# coding: utf-8
import socket
import tkinter as tk
from tkinter import ttk
import xml
import threading
import time
import socket
import json
import queue
import pandas as pd
import Graph
import Database
# import matplotlib.pyplot as plt
g = Graph.Graph()
queue1 = queue.Queue(500)
queue = queue.Queue(500)
select = ""
def server_start():
    ip_port = (socket.gethostname(), 8080)
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)     # 创建套接字
    s.connect(ip_port)
    while True:
        inp = queue.get()
        s.sendall(inp.encode())
        server_reply = s.recv(1024).decode()
        server_reply = json.loads(server_reply)
        queue1.put(server_reply)
t = threading.Thread(target=server_start)
t.start()
win = tk.Tk()
win.title("Select a country")  # Title of the window
win.geometry("500x300+200+20")
'''
pull-down menu
'''
xVariable = tk.StringVar()

# Create a pull-down menu
country=['Australia', 'Austria', 'Belarus', 'Belgium', 'Bulgaria', 'Canada', 'Croatia', 'Cyprus', 'Czechia', 'Denmark', 'Estonia', 'European Union', \
'Finland', 'France', 'Germany', 'Greece', 'Hungary', 'Iceland', 'Ireland', 'Italy', 'Japan', 'Latvia', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Malta', \
'Monaco', 'Netherlands', 'New Zealand', 'Norway', 'Poland', 'Portugal', 'Romania', 'Russian Federation', 'Slovakia', 'Slovenia', 'Spain', 'Sweden', 'Switzerland',\
 'Turkey', 'Ukraine', 'United Kingdom', 'United States of America']

com = ttk.Combobox(win, textvariable=xVariable)
com.pack()
com["value"] = country
com.current(0)  # Set a default value
com.bind("<<ComboboxSelected>>")
button1 = tk.Button(win, text="plotxy",command=lambda:g.plotxy(queue1,select))
def put_info():
    global select
    country_select = com.get()
    select = country_select
    queue.put(country_select)
#     print(country_select)
    button1.pack()
button = tk.Button(win, text="send",command=put_info)
button.pack()
win.mainloop()

